package com.lds.config.center.server.business.item.controller;

import com.lds.config.center.common.model.item.request.ItemBaseBatchCreateRequest;
import com.lds.config.center.common.model.item.request.ItemBaseBatchDeleteRequest;
import com.lds.config.center.common.model.item.request.ItemBaseBatchUpdateRequest;
import com.lds.config.center.common.model.item.request.ItemBaseCreateRequest;
import com.lds.config.center.common.model.item.request.ItemBaseDeleteRequest;
import com.lds.config.center.common.model.item.request.ItemBaseGetByIdRequest;
import com.lds.config.center.common.model.item.request.ItemBaseGetByIdsRequest;
import com.lds.config.center.common.model.item.request.ItemBaseGetByKeyRequest;
import com.lds.config.center.common.model.item.request.ItemBaseListPageRequest;
import com.lds.config.center.common.model.item.request.ItemBaseListRequest;
import com.lds.config.center.common.model.item.request.ItemBaseUpdateRequest;
import com.lds.config.center.common.model.item.response.ItemBaseBatchCreateResponse;
import com.lds.config.center.common.model.item.response.ItemBaseBatchDeleteResponse;
import com.lds.config.center.common.model.item.response.ItemBaseBatchUpdateResponse;
import com.lds.config.center.common.model.item.response.ItemBaseDeleteResponse;
import com.lds.config.center.common.model.item.response.ItemBaseListResponse;
import com.lds.config.center.common.model.item.response.ItemBaseResponse;
import com.lds.config.center.server.business.item.service.ItemBaseService;
import com.lds.management.center.common.model.db.OrderBy;
import com.lds.management.center.common.model.db.PageResult;
import com.lds.management.center.common.model.dto.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2025-06-30
 */
@Slf4j
@RestController
@RequestMapping("/api/common/item")
public class ItemBaseController {

    @Autowired
    private ItemBaseService itemBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<ItemBaseResponse> createItem(@RequestBody @Validated ItemBaseCreateRequest request) {
        return itemBaseService.createItem(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<ItemBaseBatchCreateResponse> batchCreateItem(@RequestBody @Validated ItemBaseBatchCreateRequest request) {
        return itemBaseService.batchCreateItem(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<ItemBaseDeleteResponse> deleteItem(@RequestBody ItemBaseDeleteRequest request) {
        return itemBaseService.deleteItem(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<ItemBaseBatchDeleteResponse> batchDeleteItem(@RequestBody @Validated ItemBaseBatchDeleteRequest request) {
        return itemBaseService.batchDeleteItem(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<ItemBaseResponse> updateItem(@RequestBody @Validated ItemBaseUpdateRequest request) {
        return itemBaseService.updateItem(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<ItemBaseBatchUpdateResponse> batchUpdateItem(@RequestBody @Validated ItemBaseBatchUpdateRequest request) {
        return itemBaseService.batchUpdateItem(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<ItemBaseListResponse> listItem(@RequestBody ItemBaseListRequest request) {
        return itemBaseService.listItem(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<ItemBaseListResponse> listAllItem(@RequestBody OrderBy orderBy) {
        return itemBaseService.listAllItem(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<ItemBaseResponse> getItemById(@RequestBody @Validated ItemBaseGetByIdRequest request) {
        return itemBaseService.getItemById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<ItemBaseListResponse> getItemByIds(@RequestBody @Validated ItemBaseGetByIdsRequest request) {
        return itemBaseService.getItemByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<ItemBaseResponse>> listItemPage(@RequestBody ItemBaseListPageRequest request) {
        return itemBaseService.listItemPage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated ItemBaseGetByKeyRequest request) {
        return ResultDTO.success(itemBaseService.getItemByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<ItemBaseBatchCreateResponse> batchCreateItemAsync(@RequestBody @Validated ItemBaseBatchCreateRequest request) {
        return itemBaseService.batchCreateItemAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<ItemBaseBatchDeleteResponse> batchDeleteItemAsync(@RequestBody @Validated ItemBaseBatchDeleteRequest request) {
        return itemBaseService.batchDeleteItemAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<ItemBaseBatchUpdateResponse> batchUpdateItemAsync(@RequestBody @Validated ItemBaseBatchUpdateRequest request) {
        return itemBaseService.batchUpdateItemAsync(request);
    }

}